package com.exampl.elasticsearch.demo.handler;

import com.exampl.elasticsearch.demo.repository.es.Item;
import com.exampl.elasticsearch.demo.repository.es.ItemRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * TODO(用一句话描述该文件做什么)
 *
 * @version 1.0
 * @date: 2021/01/31 10:57
 */
@RestController
@RequestMapping("item/")
public class ItemHandler {
    @Autowired
    ItemRepository itemRepository;


    @RequestMapping("save")
    public String save(Long id){
        if(id==null){
            throw new NullPointerException("id 不能为空");
        }
        Item item = new Item();
        item.setId(id);
        item.setTitle("这是个标题"+id);
        item.setCategory("分类"+id);
        item.setBrand("品牌"+id);
        item.setPrice(11.5D);
        item.setImages("no"+id);
        itemRepository.save(item);
        return "SUCCESS";
    }


    @RequestMapping("list/all")
    public Iterable listAll(){
        return  itemRepository.findAll();
    }

}
